Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support server event streams #1479

Merged
merged 31 commits into from
Jul 25, 2022
Merged

Support server event streams #1479

merged 31 commits into from
Jul 25, 2022

Conversation

82marbag
Copy link
Contributor

Support server event streams

Closes: #1157

Motivation and Context

This PR adds support for server event streams. See #1157

Description

This PR adds support for server event streams and updates the Pokemon model and service to use them

Testing

  • Run the Pokemon server and client
  • ./gradlew :codegen-server-test:test
  • ./gradlew :codegen-test:test

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@82marbag 82marbag requested review from a team as code owners June 21, 2022 17:24
Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great start! It's exciting to see this working 😄

Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might have misunderstood event stream errors, and that's what most of my comments are about. Other than errors and the removal of the event stream allow list, I think this looks good. Both of these need to be addressed before approval though.

@@ -37,3 +80,40 @@ object EventStreamNormalizer {
.build()
}
}

fun OperationShape.operationErrors(model: Model): List<Shape> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the intent for this function? The OperationIndex.getErrors already returns all the errors for the operation, right? So why does it need to be filtered by the synthetic trait? Wouldn't all of them have it since the normalizer added it to all of them?

rust-runtime/aws-smithy-http/src/event_stream/sender.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@crisidev crisidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I have added some minor comments. This PR will break as soon as you merge in the Python server, so some other adjustments are needed.

One thing I suggest you to do is to throw a CodegenException if EventStreams are used in model built with the Python plugin.

RestJsonHttpBindingResolver(codegenContext.model, ProtocolContentTypes.consistent("application/json"))
RestJsonHttpBindingResolver(codegenContext.model, ProtocolContentTypes("application/json", "application/json", "application/vnd.amazon.eventstream"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does.

import software.amazon.smithy.rust.codegen.util.hasTrait
import software.amazon.smithy.rust.codegen.util.toPascalCase

class EventStreamErrorMarshallerGenerator(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some documentation to this class and methods..

@@ -10,15 +10,42 @@
use std::time::Duration;

use crate::helpers::{client, PokemonService};
use async_stream::stream;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be aware the this file is currently symlinked inside the Python folder. You will need to copy the original implementation there since event streams are not supported yet.

Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to take a look at the codegen diff and CI results before approving, but I think overall this looks good! One question remaining that may or may not require changes.

}
fun transform(model: Model): Model = ModelTransformer.create().mapShapes(model) { shape ->
if (shape is OperationShape && shape.isEventStream(model)) {
addStreamErrorsToOperationErrors(model, shape)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this affect the top-level error, the operation error, or both? I think the intention is to only have the top-level error hold both the operation and streaming errors in it.

* Server event streams
* Rename EventStreamInput to EventStreamSender
* Make event stream errors optional
* Pokemon service model updated
* Pokemon server event handler
* Pokemon client to test event streams
* EventStreamDecorator to make optional using SigV4 signing

Closes: #1157

Signed-off-by: Daniele Ahmed <[email protected]>
Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! This is an incredible piece of engineering with a lot of cool ideas baked in. Really impressed with how quick this came together.

In the current state of the PR I can't really evaluate the changes, especially the changes around errors for event streams. Here's what I'd suggest:

  • An RFC / design doc (doesn't need to be long) or an addition to the docs folder explaining different union shape structures and the event stream types we plan to generate
  • As possible, split out the most complex pieces of code into standalone PRs with tests, eg. the changes to EventStream normalization can stand alone I think?

import software.amazon.smithy.rust.codegen.util.hasTrait
import software.amazon.smithy.rust.codegen.util.toPascalCase

class EventStreamErrorMarshallerGenerator(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this really need to inherit? can we refactor for composition?

82marbag added 8 commits July 15, 2022 10:04
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Signed-off-by: Daniele Ahmed <[email protected]>
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Daniele Ahmed and others added 2 commits July 19, 2022 19:27
Signed-off-by: Daniele Ahmed <[email protected]>
Signed-off-by: Daniele Ahmed <[email protected]>
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Signed-off-by: Daniele Ahmed <[email protected]>
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice work! 🚀

I checked out the changes locally and verified that the Amazon Transcribe streaming example still works correctly. Also looked through the generated documentation to see how the errors look there. Everything looks good to me.

Overall, I'm happy with these changes. The only snag left is that the codegen diff doesn't show a diff for a full service thanks to #1219. I think if we get #1565 merged, and then update this with the latest main, the diff will be small enough that we can see a full service diffed. Seeing that would be a nice sanity check.

I think we're very close to getting this merged. @rcoh or @Velfi, feel free to approve on my behalf if I'm not available to review with the changelog and codegen diff updates in.

CHANGELOG.next.toml Outdated Show resolved Hide resolved
CHANGELOG.next.toml Outdated Show resolved Hide resolved
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@82marbag
Copy link
Contributor Author

I tried #1565 here, but the diff of errors is still as large (20k lines). Instead, with and without #1565, I generated the whole SDK for both main and eventstreams, sorted all files and created a diff.
This is the diff without #1565. It's not large and it can be reviewed manually; the only changes are related to event streams (mainly additions).
@rcoh suggested to run semver check as well and it's all PASS

Signed-off-by: Daniele Ahmed <[email protected]>
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@82marbag 82marbag enabled auto-merge (squash) July 25, 2022 17:13
@@ -74,7 +74,7 @@ open class ServerServiceGenerator(

// Render combined errors.
open fun renderCombinedErrors(writer: RustWriter, operation: OperationShape) {
ServerCombinedErrorGenerator(coreCodegenContext.model, coreCodegenContext.symbolProvider, operation).render(writer)
/* Subclasses can override */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make it abstract?

@82marbag 82marbag merged commit 3610085 into main Jul 25, 2022
@82marbag 82marbag deleted the eventstreams branch July 25, 2022 17:24
david-perez added a commit that referenced this pull request Sep 23, 2022
…degenVisitor`

This is a holdover from when the server subproject was started. We've
never utilized this model transformer, nor will we have any use for it
now, since event stream operations are supported in the server since #1479.

See #1762 (comment)
david-perez added a commit that referenced this pull request Sep 23, 2022
…degenVisitor` (#1764)

This is a holdover from when the server subproject was started. We've
never utilized this model transformer, nor will we have any use for it
now, since event stream operations are supported in the server since #1479.

See #1762 (comment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for server event streams
5 participants